
PROGRAM _INIT
	AxisDbIndex := 1;
	HideMessageBox := 1;
	gAxisManualDisable := 0;
	AxisBase := 0;
END_PROGRAM

PROGRAM _CYCLIC
	FOR Index := 0 TO AXIS_MAX_INDEX BY 1 DO
		EnabledAxisList[Index] := 2 - gAxisCtrl[Index].Parameter.IsUsed * 2;
	END_FOR
	IF NextAxis = TRUE THEN
		IF AxisDbIndex = SYNC_MAX_INDEX THEN
			AxisDbIndex := 1;
		END_IF
		FOR AxisDbIndex := AxisDbIndex + 1 TO SYNC_MAX_INDEX BY 1 DO
			IF gAxisCtrl[AxisDbIndex].Parameter.IsUsed = 1 THEN
				EXIT;
			END_IF
		END_FOR
		AxisDbIndex := MIN(AxisDbIndex, SYNC_MAX_INDEX);
		IF gAxisCtrl[AxisDbIndex].Parameter.IsUsed = 0 THEN
			FOR AxisDbIndex := 4 TO SYNC_MAX_INDEX BY 1 DO
				IF gAxisCtrl[AxisDbIndex].Parameter.IsUsed = 1 THEN
					EXIT;
				END_IF
			END_FOR
		END_IF
		AxisDbIndex := MIN(AxisDbIndex, SYNC_MAX_INDEX);
		IF gAxisCtrl[AxisDbIndex].Parameter.IsUsed = 0 THEN
			AxisDbIndex := 0;
		END_IF
		NextAxis := FALSE;
	END_IF
	
	IF PreviousAxis = TRUE THEN
		IF AxisDbIndex = 4 THEN
			AxisDbIndex := SYNC_MAX_INDEX + 1;
		END_IF
		FOR AxisDbIndex := AxisDbIndex - 1 TO 0 BY -1 DO
			IF gAxisCtrl[AxisDbIndex].Parameter.IsUsed = 1 THEN
				EXIT;
			END_IF
		END_FOR
		AxisDbIndex := MAX(AxisDbIndex, 0);
		IF gAxisCtrl[AxisDbIndex].Parameter.IsUsed = 0 THEN
			FOR AxisDbIndex := SYNC_MAX_INDEX TO 0 BY -1 DO
				IF gAxisCtrl[AxisDbIndex].Parameter.IsUsed = 1 THEN
					EXIT;
				END_IF
			END_FOR
		END_IF
		AxisDbIndex := MAX(AxisDbIndex, 0);
		IF gAxisCtrl[AxisDbIndex].Parameter.IsUsed = 0 THEN
			AxisDbIndex := 0;
		END_IF
		PreviousAxis := FALSE;
	END_IF
	
	IF (AxisDbIndex > AXIS_MAX_INDEX) THEN
		AxisDbIndex := 0;
	ELSIF (AxisDbIndex < 0) THEN
		AxisDbIndex := AXIS_MAX_INDEX;
	END_IF

	pAxisDb ACCESS ADR(gAxisCtrl[AxisDbIndex]);
	IF 	 gAxisCtrl[AxisDbIndex].AxisRef = 0 THEN  
		pAxis   ACCESS (ADR(AxisDummy));
	ELSE  
		pAxis   ACCESS (gAxisCtrl[AxisDbIndex].AxisRef);
	END_IF                                                                         
	
	pControllerPara ACCESS ADR(gControllerPara[AxisDbIndex]);
	IF pAxisDb.AxisState.Disabled = 1 AND pAxis.nc_obj_inf.nc_obj_typ <> 4 THEN
		AllowToChangePara := 1;
	ELSE
		AllowToChangePara := 0;
	END_IF
	IF NextPage = TRUE THEN
		IF AxisIndex[5] >= 0 AND AxisIndex[5] < AXIS_MAX_INDEX THEN
			Count := 0;
			FOR Index := AXIS_MAX_INDEX TO (AxisIndex[5] + 1) BY -1 DO
				IF gAxisCtrl[Index].Parameter.IsUsed = 1 THEN
					Count := Count + 1;
				END_IF
			END_FOR
			IF Count >= 6 THEN
				AxisBase := AxisIndex[5] + 1;
			ELSE
				AxisBase := AxisIndex[Count];
			END_IF
		END_IF
		NextPage := FALSE;
	END_IF
	IF PreviousPage = TRUE THEN
		IF AxisIndex[0] > 0 THEN
			Count := 0;
			FOR AxisBase := (AxisIndex[0] - 1) TO 0 BY -1 DO
				IF gAxisCtrl[AxisBase].Parameter.IsUsed = 1 THEN
					Count := Count + 1;
					IF Count = 6 THEN
						EXIT;
					END_IF
				END_IF
			END_FOR
		END_IF
		PreviousPage := FALSE;
	END_IF
	AxisBase := MAX(0, AxisBase);
	Index2 := 0;
	FOR Index := AxisBase TO AXIS_MAX_INDEX BY 1 DO
		IF gAxisCtrl[Index].Parameter.IsUsed = 1 THEN
			AxisIndex[Index2] := Index;
			Index2 := Index2 + 1;
			IF Index2 > 5 THEN
				EXIT;
			END_IF
		END_IF
	END_FOR
	FOR Index := Index2 TO 5 BY 1 DO
		AxisIndex[Index] := -1;
	END_FOR
	IF AxisIndex[5] = -1 THEN
		AxisBase := MAX(0, AxisBase - 1);
	END_IF
	
	FOR Index := 0 TO AXIS_OVER_VIEW_MAX_INDEX BY 1 DO
		IF AxisIndex[Index] >= 0 THEN
			AxisHide[Index] := 0;
		ELSE
			AxisHide[Index] := 1;
		END_IF
	END_FOR
	
	IF AxisIndex[0] >= 0 THEN
		pAxisOverView0 ACCESS ADR(gAxisCtrl[AxisIndex[0]]);
	ELSE
		pAxisOverView0 ACCESS ADR(AxisCtrlDummy);
	END_IF
	IF AxisIndex[1] >= 0 THEN
		pAxisOverView1 ACCESS ADR(gAxisCtrl[AxisIndex[1]]);
	ELSE
		pAxisOverView1 ACCESS ADR(AxisCtrlDummy);
	END_IF
	IF AxisIndex[2] >= 0 THEN
		pAxisOverView2 ACCESS ADR(gAxisCtrl[AxisIndex[2]]);
	ELSE
		pAxisOverView2 ACCESS ADR(AxisCtrlDummy);
	END_IF
	IF AxisIndex[3] >= 0 THEN
		pAxisOverView3 ACCESS ADR(gAxisCtrl[AxisIndex[3]]);
	ELSE
		pAxisOverView3 ACCESS ADR(AxisCtrlDummy);
	END_IF
	IF AxisIndex[4] >= 0 THEN
		pAxisOverView4 ACCESS ADR(gAxisCtrl[AxisIndex[4]]);
	ELSE
		pAxisOverView4 ACCESS ADR(AxisCtrlDummy);
	END_IF
	IF AxisIndex[5] >= 0 THEN
		pAxisOverView5 ACCESS ADR(gAxisCtrl[AxisIndex[5]]);
	ELSE
		pAxisOverView5 ACCESS ADR(AxisCtrlDummy);
	END_IF
	
END_PROGRAM

PROGRAM _EXIT
	(* Insert code here *)
	 
END_PROGRAM

